package us.springcode.learn;

import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.ClassPathResource;

import us.springcode.learn.model.MyResourceTestBean;
import us.springcode.learn.model.Person;

public class IOCBeanFactoryTest {

	public static void main(String[] args) {
		DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
		XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
		int num = reader.loadBeanDefinitions(new ClassPathResource("beans.xml"));
		System.out.println("一共解析了：" + num + "个BeanDefinitions");
		
		//xml配置的bean
		Object bean = factory.getBean("person");
		if (bean != null) {
			System.out.println();
			Person p = (Person) bean;
			p.info();
		}
		
		//获取注解的bean实例
		Object beanAnotation = factory.getBean("myResourceTestBean");
		if (beanAnotation != null) {
			MyResourceTestBean p = (MyResourceTestBean) beanAnotation;
			System.out.println(p.getTestStr());
		}
	}

}
